﻿using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace NovelDB
{
    public class NHibernateHelper
    {
        private ISessionFactory _sessionFactory;
        public NHibernateHelper()
        {
            _sessionFactory = GetSessionFactory();
        }
        private ISessionFactory GetSessionFactory()
        {
            return (new Configuration()).Configure().BuildSessionFactory();
        }
        public ISession GetSession()
        {
            return _sessionFactory.OpenSession();
        }

        /// <summary>
        /// 将Schema导出到数据库中去
        /// </summary>
        public void GenerateSchema()
        {
            Configuration cfg = new Configuration();
            cfg.Configure();

            SchemaExport export = new SchemaExport(cfg);
            export.Create(true, true);
        }
    }
}
